home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11036 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Getting date in UNIX
  5. Date: 21 Mar 1996 10:58:36 -0500
  6. Organization: University of Maryland Baltimore County
  7. Message-ID: <4irubc$dkf@umbc9.umbc.edu>
  8. References: <4ik447$bn7@raffles.technet.sg> <4ike32$c8n@ccshst05.cs.uoguelph.ca>
  9. NNTP-Posting-Host: umbc9.umbc.edu
  10. NNTP-Posting-User: schlein
  11.  
  12. Leonard Sim (leonard@pacific.net.sg) wrote:
  13. >> Can anyone please inform me how to obtain the date in UNIX C??
  14. >> I just need the date in this format "dd/mm/yyyy". Thanks!!!
  15.  
  16. Toby K Hay <thay@uoguelph.ca> wrote:
  17. > I just did this for the first time using an example from my Turbo C 
  18. > reference by Herb Schildt.  (Will mentioning that name start another 
  19. > long thread on his failings?)  
  20.  
  21. Actually it will because your #include statements should be enclosed
  22. in <> instead of "".
  23.  
  24. > #include "time.h"
  25. > #include "stdio.h"
  26. > int main(void)
  27.  
  28. I find that hard to believe Schildt wrote that declaration. Perhaps you
  29. took the initiative and fixed it? Good going!
  30.  
  31. |> {  struct tm *ptr;
  32. |>    time_t lt;
  33. |> 
  34. |>   lt = time(NULL);
  35. |>   ptr = localtime(<);
  36. |>   printf(asctime(ptr));
  37.  
  38. There's just something I don't like about using printf() like that. I mean
  39. you are trying to print a string, which by the way isn't in the format the
  40. poster asked for, but don't give printf() a format specification.
  41.  
  42. I'd recommend looking at the strftime() function and building the string
  43. from scratch and then printing it.
  44.  
  45. |>   return 0;
  46. |> }
  47. -- 
  48. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  49.  
  50. Jonas J. Schlein  (schlein@gl.umbc.edu)
  51.